
import fetch from "node-fetch";
// const fetch=require('node-fetch')
// console.log(fetch)
// fetch.then(res=>console.log(res))
// var server=new http.Server();server.on("request",function(req,res){res.writeHead(200,{"content-type":"text/plain"});res.write("hello nodejs");res.end();
// });
// server.listen(3000);
class GitDevlop{
     constructor() {
        this.cookieRes=`username=gaomin; user=%22gaomin%22;`
        // await this.getCookie()
    }
    async  getCookie(){
        const response = await fetch('http://172.26.0.13:8088/backend/template_data/data?service=system.login',{method:'post',body: JSON.stringify({login_model:"inner",password:"gao897572000/",remember:true,service:"system.login",username:"gaomin"}),
            headers: {
                'Content-Type': 'application/json'
            }});
        const cookie = response.headers.get('set-cookie')
        // return cookie.split(";")[0]
        this.cookieRes=this.cookieRes+cookie.split(";")[0]
    }
    async  getTableList(version){
        console.log('cookieRes',this.cookieRes)
        let params={"service":"release.planning_list","page":1,"size":20,"search":version,"req_statu_list":[],"create_user_list":[],"is_product":null,"product_from":"","due_publish_project":"","duty_team_list":""}
        const response = await fetch('http://172.26.0.13:8088/backend/template_data/data?service=release.planning_list',
            {method:'post',
                body: JSON.stringify(params),
                headers: {
                    cookie:this.cookieRes,
                    'Content-Type': 'application/json'
                }})
        let res=await response.json()
        return res.data[0].num
        // console.log(res.data[0].num)
        // await getDetail(res.data[0].num)
        // console.log(response.json())
        // const cookie = response.headers.get('set-cookie')
        // return cookie.split(";")[0]
    }
    async  getDetail(num){
        let params={"service":"release.planning_detail","num":num}
        const response = await fetch('http://172.26.0.13:8088/backend/template_data/data?service=release.planning_detail',
            {method:'post',
                body: JSON.stringify(params),
                headers: {
                    cookie:this.cookieRes,
                    'Content-Type': 'application/json'
                }})
        let res=await response.json()
        let uiList=[]
        res.data.war_list.forEach((item)=>{
            if(item.common_is_version){
                uiList.push(item.war_artifactid)
            }
            if(item.common_is_version==='1'&&!uiList.includes('common-ui')){
                uiList.push('common-ui')
            }
        })
        // console.log("uiLIst",uiList)
        return uiList

    }
}
export default GitDevlop
// let cookieRes=`username=gaomin; user=%22gaomin%22;`




// (async () => {
//     await getCookie()
//     getTableList()
//     // console.log(cookie);
// })();